package com.example.hp.yuejian5.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hp.yuejian5.R;

import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.TrainBean;
import com.example.hp.yuejian5.model.Train_DetailModel;
import com.squareup.picasso.Picasso;
import android.support.v7.app.AppCompatActivity;

import static com.example.hp.yuejian5.other.url.TRAIN;

public class Train_DetailActivity extends AppCompatActivity {
    private String i_id, u_id;
    private Context context;
    private RetrofitListener<TrainBean> listener;

    private ImageView train_detail_pic;
    private TextView baoming;
    private SharedPreferences sp;
    private TextView train_detail_address,train_detail_notice,train_detail_price,train_detail_opentime,train_detail_closetime,traintype_detail_id,train_detail_toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_train_detail);
        Intent intent = getIntent();
        i_id = (String) intent.getStringExtra("t_id");
        sp = getSharedPreferences("user_id", Context.MODE_PRIVATE);
        u_id = sp.getString("userid", null);
        initView();
        viewListener();
        listener = new RetrofitListener<TrainBean>() {
            @Override
            public void onSuccess(TrainBean trainBean, int flag) {
                train_detail_address.setText(trainBean.getTrain_address());
                train_detail_notice.setText(trainBean.getTrain_notice());
                train_detail_price.setText(trainBean.getTrain_price());
                train_detail_opentime.setText(trainBean.getTrain_opentime());
                train_detail_closetime.setText(trainBean.getTrain_closetime());
                traintype_detail_id.setText(trainBean.getTrain_id());

                Picasso.with(context).load(TRAIN + trainBean.getTrain_pic()).into(train_detail_pic);
            }

            @Override
            public void onFail() {

            }
        };


        trainDetail();

    }

    private void initView() {
        train_detail_pic = findViewById(R.id.train_detail_pic);
        train_detail_address = findViewById(R.id.train_detail_address);
        train_detail_notice = findViewById(R.id.train_detail_notice);
        train_detail_price = findViewById(R.id.train_detail_price);
        train_detail_opentime = findViewById(R.id.train_detail_opentime);
        train_detail_closetime = findViewById(R.id.train_detail_closetime);
        traintype_detail_id = findViewById(R.id.traintype_detail_id);
        baoming=findViewById(R.id.baoming);
    }

    private void viewListener() {

        baoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent (Train_DetailActivity.this,TrainorderActivity.class);
                intent.putExtra("t_id", i_id);
                startActivity(intent);
            }
        });
    }
    private void trainDetail() {
        Train_DetailModel club_detailModel = new Train_DetailModel();
        club_detailModel.trainDetail(i_id, listener);
    }


}
